﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZWZ.Web.WebAdmin.Update
{
    public partial class BdPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ctrbtnChangePassword_Click(object sender, EventArgs e)
        {
            var MsgBox = new Codes.MessageBox(this);
            var uid = Codes.LoginHelper.CurrentUser.ID;
            //检查验证码
            if (!Codes.IdtCodeHelper.Check(ctrtxtIdentityCode.Text))
            { MsgBox.Show("验证码错误").Send(); return; }
            if (Codes.Md5Helper.GetPasswordString(ctrTxtOldPassword.Text) != Codes.LoginHelper.CurrentUser.Password)
            { MsgBox.Show("原密码错误！").Send(); return; }
            if (ctrTxtNewPassword1.Text == ctrTxtNewPassword2.Text)
            { MsgBox.Show("两次输入的密码不一致！").Send(); return; }
            var CurrentUser = ZWZ.DBProvider.DB.Ctx.User_Info.Where(i => i.ID == uid).FirstOrDefault();
            CurrentUser.Password = Codes.Md5Helper.GetPasswordString(ctrTxtNewPassword1.Text);
            ZWZ.DBProvider.DB.Ctx.SaveChanges();
            MsgBox.Show("修改成功！").Send();
        }
    }
}